package org.cll.pattern.singleton.exampletwo;


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
 * @ClassName Logger
 * @Description TODO
 * @Author Administrator
 * @Date 2024-09-10 10:25:22
 * @Version 1.0
 **/
public class Logger {

    private FileWriter writer;

    public Logger(File file) throws IOException {
        writer = new FileWriter(file, true); // true 表示追加写入
    }

    public void log(String message) throws IOException, InterruptedException {
        writer.write(message);
        writer.write(System.lineSeparator());
        writer.flush();
    }

    public void close() throws IOException {
        writer.close();
    }
}

